package com.hice.demo.sbdbra.common.util;

import com.hice.demo.sbdbra.common.util.reflection.ReflectionUtils;
import org.apache.commons.lang3.StringUtils;

public class EnumUtils {
    public EnumUtils() {
    }

    public static <E extends Enum<E>> E getEnum(E[] enumValus, String propertyName, Object value) {
        if (StringUtils.isNotBlank(propertyName) && value != null) {
            Enum[] var3 = enumValus;
            int var4 = enumValus.length;

            for (int var5 = 0; var5 < var4; ++var5) {
                Enum e = var3[var5];
                if (value.toString().equals(ReflectionUtils.getFieldValue(e, propertyName).toString())) {
                    return (E) e;
                }
            }
        }

        return null;
    }

    public static void main(String[] args) {
        Test test = (Test) getEnum(Test.values(), "type", Integer.valueOf(1));
        System.out.println(test.name);
        Test test2 = (Test) getEnum(Test.values(), "name", "aa");
        System.out.println(test2.name);
    }

    static enum Test {
        a(1, "aa"),
        b(2, "bb");

        private int type;
        private String name;

        private Test(int type, String name) {
            this.type = type;
            this.name = name;
        }

        public int getType() {
            return this.type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public String getName() {
            return this.name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
